package com.huawei;

import java.util.Scanner;

/**
 * Created by Z-hong on 2024/7/2.
 */

public class HJ5 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String in=sc.nextLine();
        char arr[]=in.toCharArray();
        int [] charCount={10,11,12,13,14,15};
        int result = 0;
        int bit=1;
        for (int i=arr.length-1;i>=0;i--){
            if(arr[i]=='x') break;
            if(arr[i] - 'A'< 0 ){
                result+= (arr[i]-'0')*bit;
            }else {
                result+= (charCount[arr[i]-'A'])*bit;
            }
            bit*=16;
        }

        System.out.println(result);

    }
}
